<?php

use Cake\Cache\Cache;
use Cake\Cache\Engine\FileEngine;
use Cake\Datasource\ConnectionManager;
use Cake\I18n\FrozenTime;
use Cake\I18n\I18n;
use Cake\I18n\Time;
use Cake\Log\Log;
use Noodlehaus\Config;

include_once dirname(__DIR__) . '/vendor/autoload.php';
define('ROOT_DIR', dirname(__DIR__));
define('TMP_DIR', dirname(__DIR__) . '/tmp');
define('CONFIG_DIR', dirname(__DIR__) . '/config');
define('SRC_DIR', dirname(__DIR__) . '/src');
$DiContainer = new \Wonfu\Core\DIContainer();
$DiContainer->useAnnotations = true;
$container = $DiContainer->build(dirname(__FILE__) . '/diconfig.php');
$baseDataBaseConfig = $container->get(Config::class)->get('database');
if ($container->get('env') == 'test') {
    ini_set('opcache.enable',0);
    ini_set('opcache.enable_cli',0);
    ini_set('opcache.revalidate_freq', 1);
}
\App\Constants\AppInfo::$container = $container;
date_default_timezone_set('Asia/Shanghai');
ConnectionManager::setConfig('default', [
    'className' => \App\Core\CakeConnectionWrapper::class,
    'driver' => \Cake\Database\Driver\Mysql::class,
    'host' => $baseDataBaseConfig['host'],
    'database' => $baseDataBaseConfig['dbname'],
    'username' => $baseDataBaseConfig['user'],
    'password' => $baseDataBaseConfig['password'],
    'port' => $baseDataBaseConfig['port'],
    'cacheMetadata' => true,
    'quoteIdentifiers' => false,
    'log' => true
]);


Cache::setConfig('default', [
    'className' => FileEngine::class,
    'duration' => '+1 year',
    'serialize' => true,
    'prefix' => 'cake_',
]);
Cache::setConfig('_cake_model_', [
    'className' => FileEngine::class,
    'duration' => '+7 day',
    'serialize' => true,
    'prefix' => 'orm_',
    'path' => ROOT_DIR . '/tmp'
]);
Log::setConfig('default', function () use ($container) {
    return $container->get(\Psr\Log\LoggerInterface::class);
});
I18n::setLocale('zh_CN');
FrozenTime::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');
return $container;